import { reqSearchList } from '@/api'

const state = {
    //搜索结果对象
    searchList: {},
}
const mutations = {
    RECEIVE_SEARCH_LIST(state, searchList) {
        state.searchList = searchList
    },
}
const actions = {
    async getSearchList({ commit }, searchParams = {}) {
        searchParams = { ...searchParams }
        Object.keys(searchParams).forEach((key) => {
            if (searchParams[key] === '') delete searchParams[key]
        })
        const res = await reqSearchList(searchParams)
        if (res.code !== 200) return console.log('请求搜索结果数据失败')
        commit('RECEIVE_SEARCH_LIST', res.data)
    },
}
const getters = {
    goodsList(state){
        return state.searchList.goodsList || []
    },
    attrsList(state){
        return state.searchList.attrsList || []
    },
    trademarkList(state){
        return state.searchList.trademarkList || []
    }
}

export default {
    state,
    mutations,
    actions,
    getters,
}
